﻿using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using PlugNT.Safe;
using PlugNT.Common;

namespace PlugNT.Custom
{
    public class SysManager
    {

        /// <summary>
        /// 错误日志路径
        /// </summary>
        public static string LogErrorPath
        {
            get { return WebConfig.RootPath + @"Logs\Error\" + DateTime.Now.ToShortDateString(); }
        }

        /// <summary>
        /// 返回编号
        /// </summary>
        /// <returns></returns>
        public static string GetNoString()
        {
            string sessionid = (System.Web.HttpContext.Current.Session == null) ? "" : System.Web.HttpContext.Current.Session.SessionID.GetHashCode().ToString();
            return Utils.GetDateTimeCode() + sessionid;
        }

        /// <summary>
        /// 写出错误信息
        /// </summary>
        /// <param name="text"></param>
        public static void LogErrorWriteln(string text)
        {
            string dic = LogErrorPath;
            string logfilepath = dic + @"\" + GetNoString() + ".txt";
            if (!Directory.Exists(dic))
            {
                Directory.CreateDirectory(dic);
            }
            if (File.Exists(logfilepath))
            {
                StreamWriter sr = File.AppendText(logfilepath);
                sr.WriteLine("\n" + DateTime.Now.ToString() + ":\n");
                sr.WriteLine(text);
                sr.Close();
            }
            else
            {
                StreamWriter sr = File.CreateText(logfilepath);
                sr.WriteLine("\n" + DateTime.Now.ToString() + ":\n");
                sr.WriteLine(text);
                sr.Close();
            }
        }
    }
}
